package com.qwert.shortlink.admin.controller;

import com.qwert.shortlink.admin.common.convention.result.Result;
import com.qwert.shortlink.admin.dto.req.group.ShortLinkGroupSaveReqDTO;
import com.qwert.shortlink.admin.dto.req.group.ShortLinkGroupSortReqDTO;
import com.qwert.shortlink.admin.dto.req.group.ShortLinkGroupUpdateReqDTO;
import com.qwert.shortlink.admin.dto.resp.group.ShortLinkGroupRespDTO;
import com.qwert.shortlink.admin.service.IGroupService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 短链接分组控制层
 * @author qwert
 * @version 1.0.0
 * @create 2024/6/26 15:15
 **/
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/shortlink/admin")
public class GroupController {

    private final IGroupService groupService;

    /**
     * 新增短链接分组
     */
    @PostMapping("/v1/group")
    public Result<Integer> saveGroup(@RequestBody ShortLinkGroupSaveReqDTO shortLinkGroupSaveReqDTO) {
        return Result.success(groupService.saveGroup(shortLinkGroupSaveReqDTO));
    }

    /**
     * 查询短链接分组
     */
    @GetMapping("/v1/group")
    public Result<List<ShortLinkGroupRespDTO>> listGroup() {
        return Result.success(groupService.listGroup());
    }

    /**
     * 短链接修改
     */
    @PutMapping("/v1/group")
    public Result<Integer> updateGroup(@RequestBody ShortLinkGroupUpdateReqDTO shortLinkGroupUpdateReqDTO) {
        return Result.success(groupService.updateGroup(shortLinkGroupUpdateReqDTO));
    }

    /**
     * 删除短链接分组
     */
    @DeleteMapping("/v1/group")
    public Result<Integer> deleteGroup(@RequestParam String gid) {
        return Result.success(groupService.deleteGroup(gid));
    }

    /**
     * 短链接分组排序
     */
    @PostMapping("/v1/group/sort")
    public Result<Boolean> sortGroup(@RequestBody List<ShortLinkGroupSortReqDTO> linkGroupSortReqDTOList) {
        return Result.success(groupService.sortGroup(linkGroupSortReqDTOList));
    }
}
